package com.atguigu.gulimall.member.web;

import com.alibaba.fastjson.JSON;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.member.feign.coupon.OrderFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ShiJieLin
 * @Date 2022/5/2 21:21
 * @Version 1.0
 */
@Controller
@Slf4j
public class MemberWebController {

    @Autowired
    OrderFeignService orderFeignService;

    /** 会员点击我的订单，查询出会员的所有订单项目
     * @param pageNum 当前页码
     * @param model
     * @return
     */
    @GetMapping(value = "/memberOrder.html")
    public String memberOrderPage(@RequestParam(name = "pageNum", defaultValue = "1") String pageNum,
                                   Model model) {

        Map<String, Object> parms = new HashMap<>();
        parms.put("page", pageNum);

        R orderInfo = orderFeignService.listWithItem(parms);
        model.addAttribute("orders", orderInfo);
        System.out.println("调用远程订单服务" + JSON.toJSONString(orderInfo));
        return "shoppingList";
    }


}
